package fastjson2

import com.alibaba.fastjson2.*

fun main() {
    val user1 = User(1, "a")
    val user2 = User(2, "b")

    val json1 = user1.toJSONString()
    println(json1)

    val users = listOf(user1, user2)
    println(users)
    val jsonArray1 = users.toJSONString()
    println(jsonArray1)



    val str1 = "{\"id\":1,\"name\":\"a\"}"
    println(str1.to<User>())

    val str2 = "[{\"id\":1,\"name\":\"a\"},{\"id\":2,\"name\":\"b\"}]"
    println(str2.into<List<User>>())
}

class User(
    var id: Int,
    var name: String
) {
    override fun toString(): String {
        return "id=${id}, name=${name}"
    }
}